//
//  MAPackage.h
//  MiniApp
//
//  Created by enigmaliang on 2018/11/20.
//  Copyright © 2018 tencent. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "UIViewController+MiniApp.h"

#define JSSDK_LOGIC_JS          @"QLogic.js"        // WAService.js
#define JSSDK_PAGEFRAME_HTML    @"QPageFrame.html"  // WAPageFrame.html
#define JSSDK_VIEW_JS           @"QView.js"         // WAWebview.js
#define JSSDK_VCONSOLE_JS       @"QVConsole.js"     // WAVConsole.js
#define JSSDK_WORKER_JS         @"QWorker.js"       // WAWorker.js
#define JSSDK_REMOTEDEBUG_JS    @"QRemoteDebug.js"  // WARemoteDebug.js
#define JSSDK_WEBVIEW_JS        @"QWebview.js"

#define APKG_APPCONFIG_JSON     @"app-config.json"
#define APKG_APPSERVICE_JS      @"app-service.js"
#define APKG_PAGEFRAME_HTML     @"page-frame.html"  // 主包是html
#define APKG_PAGEFRAME_JS       @"page-frame.js"    // 分包是js
#define APKG_APPWXSS_JS         @"app-wxss.js"
#define APKG_WORKER_JS          @"workers.js"

typedef enum : NSUInteger {
    ShowHomeButton_False = 0,//不展示
    ShowHomeButton_True = 1,//展示
    ShowHomeButton_NotConfig = 2,//没有配置是否展示
} HomeButtonConfigState;

NS_ASSUME_NONNULL_BEGIN

@class MABaseApplication;

@interface MAPackage : NSObject

- (instancetype)initWithPath:(NSString *)path application:(MABaseApplication *)application;

@property (nonatomic, weak) MABaseApplication* application;

@property (nonatomic, readonly) NSDictionary *appConfig;

/**
 通过传入的App获取对应的skd配置。SDK可取配置见MASDKConfig_XXXKey
 
 @param app 对应app
 @return 配置dict
 */
+ (NSDictionary *)fetchSdkConfigForApp:(MABaseApplication *)app;

+ (NSString *)WAWebviewScriptWithSDKPath:(NSString *)sdkPath;

+ (NSString *)WAVConsoleScriptWithSDKPath:(NSString *)sdkPath;

+ (NSString *)WAServiceScriptWithSDKPath:(NSString *)sdkPath;

+ (NSString *)WAWorkerScriptWithSDKPath:(NSString *)sdkPath forApp:(MABaseApplication *)app;

+ (NSString *)WARemoteDebugWithSDKPath:(NSString *)sdkPath;

+ (NSString *)QWebviewWithSDKPath:(NSString *)sdkPath;

- (NSString *)entryPagePathWithoutParam;

- (NSString *)entryPagePath;

// 判断是否为首页，有两种情况，一种是后台下发的直进页面，另外一种是config配置的首页
- (BOOL)isEntryPage:(NSString *)pageURL;
// 判断 pageURL 是否 config 配置的首页
- (BOOL)isConfigEntryPage:(NSString *)pageURL;
// 获取 config 配置的首页
- (NSString *)appConfigEntryPagePath;

// 全局配置 - 是否展示home按钮
- (bool)showHomeButtonGlobal;
// 页面配置 - 是否展示home按钮
- (HomeButtonConfigState)showHomeButtonInPage:(NSString *)pagePath;

- (BOOL)hasTabBar;

- (BOOL)isTabBarEntry:(NSString *)url;

- (NSDictionary *)tabBarInfo;

- (NSDictionary *)titleBarInfo;

- (NSDictionary *)globalWindowConfig;

- (NSDictionary *)pageWindowConfigForPageURL:(NSString *)pageURL;

- (NSString *)injectAppConfigJsonScript;

+ (NSString *)injectJSSDKScript:(BOOL)isWebContainer;

+ (NSString *)copyQQConfigToWxConfigScript;

- (NSString *)appServiceScript;

- (NSString *)appWxssScript;

- (NSString *)apkgWorksJS;

- (NSString *)packagePageFrame;

- (NSString *)pageJSStrFromPath:(NSString *)pagePath;

- (NSString *)getPackagePath;

+ (void)WAPageFrameHtmlWithSDKPath:(NSString *)sdkPath
                           appInfo:(MAAppInfo *)appInfo
                   completionBlock:(void(^)(NSString *result, NSString *updateJSSDKPath))completionBlock;

- (BOOL)isVersionMatch:(NSString *)pagePath;

- (BOOL)isPageExist:(NSString *)pagePath;

- (void)preparePage:(NSString *)pagePath completionBlock:(void(^)(NSError *error))completionBlock;

- (NSString *)rootPathOfPageURL:(NSString *)pagePath;

// 分包是否为独立分包
- (BOOL)isIndependentSubPackage:(NSString *)rootPath;

+ (NSString *)readFileContent:(NSString *)path;

- (BOOL)isCustomNavigationStyleForPageURL:(NSString *)pageURL; // navigationStyle需要支持到页面

- (MANavTextStyle)navigationTextStyleOfPageURL:(NSString *)pageURL;

/// 更改某个page的navigationStyle配置，navigationStyle的可选值是default或custom
/// @param pageURL 唯一标识page的URL
/// @param toCustom 是否把该page的navigationStyle配置改为custom，如果toCustom为YES则修改为custom否则修改为default
- (void)configNavigationStyleOfPageURL:(NSString *)pageURL toCustom:(BOOL)toCustom;

@end

@interface MAPackage (DeveloperTool)

+ (void)setEnableVConsole:(BOOL)isEnable appInfo:(MAAppInfo *)appInfo;

+ (BOOL)isEnableVConsoleWithAppInfo:(MAAppInfo *)appInfo;

@end

@interface MAPackage (NetworkTimeout)

/// qq.request() 的超时时间
@property (nonatomic, readonly) NSTimeInterval requestTimeout;

/// qq.downloadFile() 的超时时间
@property (nonatomic, readonly) NSTimeInterval downloadFileTimeout;

/// qq.uploadFile() 的超时时间
@property (nonatomic, readonly) NSTimeInterval uploadFileTimeout;

/// qq.connectSocket() 的超时时间
@property (nonatomic, readonly) NSTimeInterval connectSocketTimeout;

@end

NS_ASSUME_NONNULL_END
